import { createRouter, createWebHashHistory } from 'vue-router'
import { isString } from 'lodash-es'
import { genRoutes } from './utils/scan'

const router = createRouter({
  history: createWebHashHistory(),
  routes: genRoutes()
})

router.beforeEach((_to, _from, next) => {
  return next()
})

router.afterEach((to) => {
  const title = isString(to.meta?.title) ? to.meta.title : 'Tetap-Cut'
  if (!title) return true
  document.title = title
})

export default router
